package com.atguigu.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.atguigu.dao.MemberDao;
import com.atguigu.pojo.Member;
import com.atguigu.service.MemberService;
import com.atguigu.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {
    @Autowired
    MemberDao memberDao;

    @Override
    public Member getMemberByTelephone(String telephone) {
        return memberDao.findByTelephone(telephone);
    }

    @Override
    public void save(Member member) {
        memberDao.add(member);
    }

    @Override
    public List<Integer> getMemberCountByMonth(List<String> months) {
        List<Integer> counts=new ArrayList<>();
        for (String month : months) {
           String lastDayForThisMonth= DateUtils.getLastDayOfMonth(month);
            counts.add( memberDao.getMemberCountByMonth(lastDayForThisMonth));
        }
        return counts;
    }
}
